﻿<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" Title="用户推荐" %>

<script runat="server">

	protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
	{
		if (e.CommandName == "CancelView")
			ListView1.SelectedIndex = -1;
		else if (e.CommandName == "BlockIP" && e.Item.ItemType == ListViewItemType.DataItem)
		{
			int id = int.Parse(e.CommandArgument.ToString());
			string ip = null;
			
			using (TDataContext db = new TDataContext())
			{
				TUserRecommend tur = db.TUserRecommends.First(ur => ur.Id == id);
				ip = tur.UserIp;
			}

			TIpUtility.Block(ip, false);
			ListView1.DataBind();
		}
	}
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
	<asp:LinqDataSource ID="LinqDataSource1" runat="server" 
		ContextTypeName="Xpus.YouYTube.Data.TDataContext" EnableDelete="True" OrderBy="AddedTime" 
		TableName="TUserRecommends">
	</asp:LinqDataSource>
	
	<asp:ListView ID="ListView1" runat="server" DataKeyNames="Id" 
		DataSourceID="LinqDataSource1" onitemcommand="ListView1_ItemCommand">
		<LayoutTemplate>
			<div ID="itemPlaceholderContainer" runat="server" style="">
				<div ID="itemPlaceholder" runat="server" />
			</div>
			<div style="">
				<asp:DataPager ID="DataPager1" runat="server">
					<Fields>
						<asp:NextPreviousPagerField ShowFirstPageButton="true" ShowNextPageButton="false" FirstPageText="第一页" PreviousPageText="上一页" />
						<asp:NumericPagerField />
						<asp:NextPreviousPagerField ShowPreviousPageButton="false" ShowLastPageButton="true" NextPageText="下一页" LastPageText="最后一页" />
					</Fields>
				</asp:DataPager>
			</div>
		</LayoutTemplate>
		<EmptyDataTemplate>
			<span>无数据。</span>
		</EmptyDataTemplate>
		<ItemTemplate>
			<p><%# HttpUtility.HtmlEncode(Eval("Title").ToString()) %></p>
			<p><%# HttpUtility.HtmlEncode(Eval("Description").ToString()) %></p>
			<p><a href='<%# Eval("Source") %>' target="_blank"><%# HttpUtility.HtmlEncode(Eval("Source").ToString()) %></a></p>
			<p><%# HttpUtility.HtmlEncode(Eval("EmbeddedCode").ToString()) %></p>
			<p>[<%# ((DateTime)Eval("AddedTime")).ToString("yyyy-MM-dd HH:mm:ss") %>]
			<%# HttpUtility.HtmlEncode(Eval("UserName").ToString()) %>
			<a href='<%# Eval("UserUrl") %>'><%# HttpUtility.HtmlEncode(Eval("UserUrl").ToString()) %></a></p>
			<p>IP: [<%# Eval("UserIp") %>]
			<%# TIpUtility.IsIpBlocked(Eval("UserIp").ToString(), false) ? "已屏蔽" : "" %>
			<asp:LinkButton runat="server" CommandName="BlockIP" CommandArgument='<%# Eval("Id") %>' Text="屏蔽该IP"></asp:LinkButton>
			</p>
			<p>[<asp:LinkButton runat="server" CommandName="Delete" Text="删除"></asp:LinkButton>]
			[<asp:LinkButton runat="server" CommandName="Select" Text="查看详细"></asp:LinkButton>]
			[<a href='<%# "AddUserRecommendVideo.aspx?id=" + Eval("Id") %>'>添加到视频库</a>]</p>
		</ItemTemplate>
		<SelectedItemTemplate>
			<p><%# HttpUtility.HtmlEncode(Eval("Title").ToString()) %></p>
			<p><%# HttpUtility.HtmlEncode(Eval("Description").ToString()) %></p>
			<p><a href='<%# Eval("Source") %>' target="_blank"><%# HttpUtility.HtmlEncode(Eval("Source").ToString()) %></a></p>
			<p><%# Eval("EmbeddedCode") %></p>
			<p>[<%# ((DateTime)Eval("AddedTime")).ToString("yyyy-MM-dd HH:mm:ss") %>]
			<%# HttpUtility.HtmlEncode(Eval("UserName").ToString()) %>
			<a href='<%# Eval("UserUrl") %>'><%# HttpUtility.HtmlEncode(Eval("UserUrl").ToString()) %></a></p>
			<p>IP: [<%# Eval("UserIp") %>]
			<%# TIpUtility.IsIpBlocked(Eval("UserIp").ToString(), false) ? "已屏蔽" : "" %>
			<asp:LinkButton runat="server" CommandName="BlockIP" CommandArgument='<%# Eval("Id") %>' Text="屏蔽该IP"></asp:LinkButton></p>
			<p>[<asp:LinkButton runat="server" CommandName="Delete" Text="删除"></asp:LinkButton>]
			[<asp:LinkButton runat="server" Text="关闭查看" CommandName="CancelView"></asp:LinkButton>]
			[<a href='<%# "AddUserRecommendVideo.aspx?id=" + Eval("Id") %>'>添加到视频库</a>]</p>
		</SelectedItemTemplate>
		<ItemSeparatorTemplate><hr /></ItemSeparatorTemplate>
	</asp:ListView>
	
</asp:Content>

